﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class regist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        cn.ConnectionString = "Data Source=.;Initial Catalog=HotelManagement;Integrated Security=True";
        SqlCommand cmd=new SqlCommand ();
        cmd .Connection =cn ;
        cmd.CommandText = "Insert into [customer]" + "([name],[idcard],[teliphone],[pasword])" + "VALUES (@name,@idcard,@teliphone,@pasword)";
        cmd .Parameters.Add ("@name",System.Data.SqlDbType.NChar ,100).Value =name.Text ;
        cmd.Parameters.Add("@idcard", System.Data.SqlDbType.NChar, 100).Value = idcard.Text;
        cmd.Parameters.Add("@teliphone", System.Data.SqlDbType.NChar,11).Value = teliphone.Text;
        cmd.Parameters.Add("@pasword", System.Data.SqlDbType.NChar, 100).Value = pasword.Text;
        cn .Open ();
        int result = cmd.ExecuteNonQuery();
        cn .Close ();
        string msg;
        if (result > 0)
        {
            msg = "<script>alert('注册成功！')</script>";
            Response.Redirect("Login.aspx");
        }
        else msg = "<script>alert(注册失败！)</script>";
        Literal lit = new Literal();
        lit.Text = msg;
        Page.Controls.Add(lit);
    }
}